import actionType from './actionTypes'
import {loginRequest} from '../request'


const startLogin = () => {
    return {
        type: actionType.START_LOGIN
    }
}

const loginFalid = () => {
    return {
        type: actionType.FALID_LOGIN
    }
}

const loginSuccess = (userInfo) => {
    return {
        type: actionType.SUCCESS_LOGIN,
        payload: {userInfo}
    }
}

const login = (userInfo) => {
    return dispatch => {
        dispatch(startLogin())
        loginRequest(userInfo)
        .then(res=>{
            dispatch(loginSuccess(res))
        }).catch(err=>{
            dispatch(loginFalid())
        })
    }
}

const loginOut = () => {
    return dispatch => {
        dispatch(loginFalid())
    }
}

export {
    login,
    loginOut
}